package com.niit.order.pojo;

import com.niit.order.myImpl.ConcreteCommand;
import rx.Observable;
import rx.Subscriber;

/**客户端
 * @author yaojianfeng
 */
public class Client {
    public static void main(String[] args) {
        Client client = new Client();
         client.invokerTest();
//        client.observableTest();

    }


    /**
     * 创建了一个简单的事件源 observable, —个对事件传递内容输出的订阅者 subscriber
     * 通过 observable.subscribe (subscriber)来触发事件的发布
     */
    public void observableTest() {
        //创建事件源
        Observable<String> objectObservable = Observable.create(subscriber -> {
            subscriber.onNext("Hello RxJava");
            subscriber.onNext("I am Jeff");
            subscriber.onCompleted();
        });
        //创建订阅者
        Subscriber<String> subscriber = new Subscriber<>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onNext(String str) {
                System.out.println("Subscriber: " + str);
            }
        };
        //订阅
        objectObservable.subscribe(subscriber);
    }

    /**
     * 客户端通过调用者来执行命令
     */
    public void invokerTest() {
        Receiver receiver = new Receiver();
        ConcreteCommand command = new ConcreteCommand(receiver);
        Invoker invoker = new Invoker();
        invoker.setCommand(command);
        invoker.action();
    }
}
